/**
 * 
 */
package com.munoor.dalai.client.presenter;

import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.munoor.dalai.client.event.AJAXCallEvent;
import com.munoor.dalai.client.event.AJAXCallEventHandler;
import com.munoor.dalai.client.event.AJAXReturnEvent;
import com.munoor.dalai.client.event.AJAXReturnEventHandler;

/**
 * @author Osho
 * 
 */
public class BusyIndicatorPresenter implements Presenter {
	public interface Display {
		void show();

		void hide();

		Widget asWidget();
	}

	private final SimpleEventBus eventBus;
	private Display display;

	public BusyIndicatorPresenter(SimpleEventBus eventBus, Display view) {
		this.eventBus = eventBus;
		this.display = view;
		bind();
	}

	public void bind() {
		eventBus.addHandler(AJAXReturnEvent.TYPE, new AJAXReturnEventHandler() {
			@Override
			public void onAJAXReturn(AJAXReturnEvent event) {
					display.hide();
			}
		});
		eventBus.addHandler(AJAXCallEvent.TYPE, new AJAXCallEventHandler() {
			@Override
			public void onAJAXCall(AJAXCallEvent event) {
				display.show();
			}
		});
	}

	public void go(HasWidgets container) {
		// nothing to do
	}
}
